package com.zf.lease.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.zf.lease.service.ICustomerContractService;
import com.zf.lease.service.IRoomContractService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zf.common.annotation.Log;
import com.zf.common.core.controller.BaseController;
import com.zf.common.core.domain.AjaxResult;
import com.zf.common.enums.BusinessType;
import com.zf.lease.domain.Contract;
import com.zf.lease.service.IContractService;
import com.zf.common.utils.poi.ExcelUtil;
import com.zf.common.core.page.TableDataInfo;

/**
 * 契约Controller
 * 
 * @author rxf
 * @date 2024-09-28
 */
@RestController
@RequestMapping("/lease/contract")
public class ContractController extends BaseController
{
    @Autowired
    private IContractService contractService;

    /**
     * 查询契约列表
     */
    @PreAuthorize("@ss.hasPermi('lease:contract:list')")
    @GetMapping("/list")
    public TableDataInfo list(Contract contract)
    {
        startPage();
        List<Contract> list = contractService.selectContractList(contract);
        return getDataTable(list);
    }

    /**
     * 导出契约列表
     */
    @PreAuthorize("@ss.hasPermi('lease:contract:export')")
    @Log(title = "契约", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Contract contract)
    {
        List<Contract> list = contractService.selectContractList(contract);
        ExcelUtil<Contract> util = new ExcelUtil<Contract>(Contract.class);
        util.exportExcel(response, list, "契约数据");
    }

    /**
     * 获取契约详细信息
     */
    @PreAuthorize("@ss.hasPermi('lease:contract:query')")
    @GetMapping(value = "/{contractId}")
    public AjaxResult getInfo(@PathVariable("contractId") Long contractId)
    {
        return success(contractService.selectContractByContractId(contractId));
    }

    /**
     * 新增契约
     */
    @PreAuthorize("@ss.hasPermi('lease:contract:add')")
    @Log(title = "契约", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Contract contract)
    {
        return toAjax(contractService.insertContract(contract));
    }

    /**
     * 修改契约
     */
    @PreAuthorize("@ss.hasPermi('lease:contract:edit')")
    @Log(title = "契约", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Contract contract)
    {
        return toAjax(contractService.updateContract(contract));
    }

    /**
     * 删除契约
     */
    @PreAuthorize("@ss.hasPermi('lease:contract:remove')")
    @Log(title = "契约", businessType = BusinessType.DELETE)
	@DeleteMapping("/{contractIds}")
    public AjaxResult remove(@PathVariable Long[] contractIds)
    {
        return toAjax(contractService.deleteContractByContractIds(contractIds));
    }
}
